package com.longe.esaypoi.exportexcel;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.longe.entity.Goods;
import com.longe.entity.Proprietor;
import com.longe.entity.Shop;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class ThreeSimpleDemo {

    public static void main(String[] args) throws Exception {

        List<Shop> list = new ArrayList<>();

        Goods goods1 = new Goods("小棕瓶", 500, 1000);
        Goods goods2 = new Goods("小黑瓶", 300, 800);
        List<Goods> goodsList1 = new ArrayList<>();
        goodsList1.add(goods1);
        goodsList1.add(goods2);

        Proprietor proprietor1 = new Proprietor("张三", 10);
        Shop shop1 = new Shop("城西银泰", "余杭塘路", proprietor1, goodsList1);

        Goods goods3 = new Goods("小棕瓶", 300, 900);
        Goods goods4 = new Goods("小黑瓶", 100, 700);
        List<Goods> goodsList2 = new ArrayList<>();
        goodsList2.add(goods3);
        goodsList2.add(goods4);

        Proprietor proprietor2 = new Proprietor("李四", 20);
        Shop shop2 = new Shop("西溪银泰", "黄龙路", proprietor2, goodsList2);

        list.add(shop1);
        list.add(shop2);

        ExportParams exportParams = new ExportParams("测试稍微复杂导出", "firstSheet", ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, Shop.class, list);

        FileOutputStream fos = new FileOutputStream("D:\\TEST_EASY_POI\\EXPORT\\threeTestExport.xlsx");
        workbook.write(fos);
        fos.close();
    }
}
